<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<title></title>
<meta name="Generator" content="Cocoa HTML Writer">
<meta name="CocoaVersion" content="949.46">
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}
p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Arial}
p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #000000}
p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #000000; min-height: 12.0px}
p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #bf0000}
p.p7 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; color: #000000; min-height: 14.0px}
span.s1 {font: 18.0px Helvetica}
span.s2 {color: #0000bf}
span.s3 {color: #007300}
span.s4 {color: #000000}
span.s5 {color: #606060}
span.Apple-tab-span {white-space:pre}
</style>
</head>
<body>
<p class="p1"><span class="s1"><b>SLOnset<span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span></b></span><b>experimental time domain onset detector</b></p>
<p class="p2"><br></p>
<p class="p3"><b>SLOnset.kr(input, memorysize1=20, before=5,after=5, threshold=10, hysteresis=10, mul = 1.0, add = 0.0)</b></p>
<p class="p2"><br></p>
<p class="p1">Purely time domain onset detector</p>
<p class="p2"><br></p>
<p class="p1">Works well for loud signals but fainter onsets are missed, and really loud onsets lead to multiple triggers.<span class="Apple-converted-space"> </span></p>
<p class="p2"><br></p>
<p class="p1">(my note: needs some sort of log amplitude correction?)</p>
<p class="p2"><br></p>
<p class="p4">(</p>
<p class="p4">x = {<span class="s2">arg</span> threshold=10.0;<span class="Apple-converted-space"> </span></p>
<p class="p5"><br></p>
<p class="p4"><span class="s2">var</span> input, onsets;<span class="Apple-converted-space"> </span></p>
<p class="p5"><br></p>
<p class="p4">input = <span class="s2">SoundIn</span>.ar(0);<span class="Apple-converted-space"> </span></p>
<p class="p5"><br></p>
<p class="p4">onsets= <span class="s2">SLOnset</span>.kr(input,20,5,5,threshold);<span class="Apple-converted-space"> </span></p>
<p class="p5"><br></p>
<p class="p4"><span class="s2">Out</span>.ar(0, <span class="s2">SinOsc</span>.ar(440,0,0.1)*<span class="s2">Decay2</span>.ar(<span class="s2">K2A</span>.ar(onsets), 0.01, 0.1));<span class="Apple-converted-space"> </span></p>
<p class="p5"><br></p>
<p class="p4">}.play;</p>
<p class="p4">)</p>
<p class="p5"><br></p>
<p class="p5"><br></p>
<p class="p4">x.set(<span class="s3">\threshold</span>, 10.0)</p>
<p class="p5"><br></p>
<p class="p5"><br></p>
<p class="p4">x.free;</p>
<p class="p5"><br></p>
<p class="p5"><br></p>
<p class="p6"><span class="s4">b = </span><span class="s2">Buffer</span><span class="s4">.read(s,</span><span class="s5">"sounds/a11wlk01.wav"</span><span class="s4">); </span>// remember to free the buffer later.</p>
<p class="p6"><span class="s4">b = </span><span class="s2">Buffer</span><span class="s4">.read(s,</span><span class="s5">"sounds/break2"</span><span class="s4">); </span>// remember to free the buffer later.</p>
<p class="p7"><br></p>
<p class="p7"><br></p>
<p class="p4">(</p>
<p class="p4">x = {<span class="s2">arg</span> threshold=10.0, hysteresis=20;<span class="Apple-converted-space"> </span></p>
<p class="p5"><br></p>
<p class="p4"><span class="s2">var</span> input, onsets;<span class="Apple-converted-space"> </span></p>
<p class="p5"><br></p>
<p class="p4">input = <span class="s2">PlayBuf</span>.ar(1, b, <span class="s2">BufRateScale</span>.kr(b), loop:1);</p>
<p class="p5"><br></p>
<p class="p4">onsets= <span class="s2">SLOnset</span>.kr(input,20,5,5,threshold,hysteresis);<span class="Apple-converted-space"> </span></p>
<p class="p5"><br></p>
<p class="p4"><span class="s2">Out</span>.ar(0, input + (<span class="s2">SinOsc</span>.ar(440,0,0.1)*<span class="s2">Decay2</span>.ar(<span class="s2">K2A</span>.ar(onsets), 0.01, 0.05)));<span class="Apple-converted-space"> </span></p>
<p class="p5"><br></p>
<p class="p4">}.play;</p>
<p class="p4">)</p>
<p class="p5"><br></p>
<p class="p5"><br></p>
<p class="p6">//by setting these appropriately can get somewhere...</p>
<p class="p4">x.set(<span class="s3">\threshold</span>, 50.0)</p>
<p class="p4">x.set(<span class="s3">\hysteresis</span>, 10.0)</p>
<p class="p5"><br></p>
<p class="p4">b.free;</p>
</body>
</html>
